using Clancy.Data;
using Clancy.Interfaces;
using System;
using System.IO;
using System.Threading.Tasks;

namespace Clancy.Bl.VideoProvider
{
    internal class RecordingItemFactory : IRecordingItemFactory
    {
        public async Task<IRecording> CreateRecordingItem(ISurveilanceObject survObj, string fullPath)
        {
            if (!File.Exists(fullPath))
                return null;

            DateTime timestamp = File.GetCreationTime(fullPath);

            TimeSpan duration;
            byte[] thumbnail;

            using (VideoFilePropertyProvider videoFilePropertyProvider = new VideoFilePropertyProvider(fullPath))
            {
                duration = videoFilePropertyProvider.Duration;
                thumbnail = await videoFilePropertyProvider.GetThumbnailIconAsJpegByteArray(survObj.PrefetchTime);
            }

            return new RecordingItem(survObj, fullPath, timestamp, duration, thumbnail);
        }
    }
}